﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using KeaoBase;

namespace KeaoMDS.InfoManage
{
    public partial class ZiDian : BaseForm
    {
        public ZiDian()
        {
            InitializeComponent();
        }

        private void menu_1_xinzeng_Click(object sender, EventArgs e)
        {
            if (!string.Format("{0}", KeaoUtils._CurrentUserRow["juesequanxian"]).Contains("基础数据配置"))
            {
                KeaoUtils.ShowInfoMessage("该用户没有操作权限。");
                return;
            }
            ZiDianBianJi ziDianBianJi = new ZiDianBianJi();
            if (ziDianBianJi.ShowDialog() == DialogResult.OK)
            {
                BindInfo();
            }
        }

        private void menu_1_xiugai_Click(object sender, EventArgs e)
        {
            if (!string.Format("{0}", KeaoUtils._CurrentUserRow["juesequanxian"]).Contains("基础数据配置"))
            {
                KeaoUtils.ShowInfoMessage("该用户没有操作权限。");
                return;
            }
            if (dataGridView1.SelectedRows.Count == 0)
            {
                return;
            }
            ZiDianBianJi ziDianBianJi = new ZiDianBianJi(dataGridView1.SelectedRows[0]);
            if (ziDianBianJi.ShowDialog() == DialogResult.OK)
            {
                BindInfo();
            }
        }

        private void menu_1_shanchu_Click(object sender, EventArgs e)
        {
            if (!string.Format("{0}", KeaoUtils._CurrentUserRow["juesequanxian"]).Contains("基础数据配置"))
            {
                KeaoUtils.ShowInfoMessage("该用户没有操作权限。");
                return;
            }
            if (dataGridView1.SelectedRows.Count == 0)
            {
                return;
            }

            if (KeaoUtils.ShowQuestionMessage("确定要删除选中的数据吗？") == DialogResult.Yes)
            {
                TableRow delRow = new TableRow() { TableName="tbl_zidian", ID = string.Format("{0}",dataGridView1.SelectedRows[0].Cells["col_id"].Value) };
                if (KeaoUtils._DB.DeleteRowByID(delRow)>0)
                {
                    BindInfo();
                }
            }
        }

        private void ZiDian_Load(object sender, EventArgs e)
        {
            dataGridView1.AutoGenerateColumns = false;
            BindInfo();
        }

        private void BindInfo()
        {
            Dictionary<string, string> orderBys = new Dictionary<string, string>();
            orderBys.Add("fenzu", "asc");
            orderBys.Add("shijian", "asc");
            DataTable Dt = KeaoUtils._DB.GetDataTableByCondition("tbl_zidian", orderBys);
            dataGridView1.DataSource = Dt;
        }

        private void dataGridView1_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);
        }
    }
}
